home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 1
/
Cream of the Crop 1.iso
/
UTILITY
/
BANDOG.ARJ
/
CERBERUS.ASM
next >
Wrap
Assembly Source File
|
1991-01-05
|
9KB
|
186 lines
TITLE CERBERUS
; In Greek myths, on guard before the gate to the underworld sits Cerberus, the
; three-headed, dragon-tailed dog, who permits all spirits to enter, but none
; to return.
;
; CERBERUS.ASM prompts the user to enter a password. The user is allowed three
; tries to get the password correct. If the user does not enter the correct
; password after three tries, the system performs a warm boot. The user cannot
; break out using either Control-C or Control-Break. Periods are echoed for
; the password input.
_TEXT SEGMENT
ASSUME CS:_TEXT,DS:_TEXT,SS:_TEXT
ORG 100h
BEGIN:
MOV CX,3 ; Load number of tries into CX
LEA SI,MESSAGE1 ; Print system message
CALL WRITELN
PASSWD_LOOP:
LEA SI,PROMPT ; Print the prompt
CALL WRITELN
LEA DI,BUFFER ; Get string input into BUFFER
CALL GETSTR
XOR AL,AL ; Set return code to 0
LEA SI,PASSWORD ; Compare password and buffer
CALL STRCMP
JC FINISH ; Return to DOS if strings are equal
LEA SI,MESSAGE2 ; Inform user of incorrect input
CALL WRITELN
LOOP PASSWD_LOOP ; Loop until out of tries
LEA SI,MESSAGE3 ; Print reboot message
CALL WRITELN
DB 0EAh,00h,00h,0FFh,0FFh ; JMP FFFF:0000
FINISH:
MOV AH,4Ch ; Exit to DOS
INT 21h
;-----------------------------------------------------------------------;
; This procedure outputs a string. ;
; ;
; Uses: ;
; SI Address of string ;
; ;
; Returns: ;
; Nothing ;
;-----------------------------------------------------------------------;
WRITELN:
PUSH AX ; Save AX
PUSH SI ; Save SI
WRITELN_LOOP:
MOV AL,[SI] ; Display character at SI
CMP AL,0 ; Have we reached the null terminator?
JE EXIT_WRITELN ; Yes, return to calling function
INT 29h ; Call fast putchar function
INC SI ; Increment pointer
JMP WRITELN_LOOP ; Repeat for remaining characters
EXIT_WRITELN:
POP SI ; Restore SI
POP AX ; Restore AX
RET
;-----------------------------------------------------------------------;
; This procedure reads in a string from the standard input device. ;
; Extended keys, backspaces, and carriage returns are the only keys ;
; processed. All other input is stored in a buffer. ;
; ;
; Uses: ;
; DI Address of string ;
; GET_CHAR Reads a character from the standard input ;
; ;
; Returns: ;
; Nothing ;
;-----------------------------------------------------------------------;
GETSTR:
PUSH AX ; Save AX
PUSH SI ; Save SI
PUSH DI ; Save DI
GETSTR_LOOP:
CALL GET_CHAR ; Get a character
CMP AL,0 ; Is the character a null?
JNE IS_CTRL_C ; No, check for Control-C
CALL GET_CHAR ; Get scan code for extended key
JMP GETSTR_LOOP ; Loop again
IS_CTRL_C:
CMP AL,3 ; Is the character a Control-C?
JNE IS_BS ; No, check for backspace
JMP GETSTR_LOOP ; Loop again
IS_BS:
CMP AL,8 ; Is the character a backspace?
JNE IS_CR ; No, check for carriage return
CMP DI,OFFSET BUFFER ; Are we at beginning of input buffer?
JE GETSTR_LOOP ; Yes, do not erase last character
LEA SI,BACKSPACE ; No, erase last character entered
CALL WRITELN
DEC DI ; Decrement pointer
JMP GETSTR_LOOP ; Loop again
IS_CR:
CMP AL,13 ; Is the character a carriage return?
JE EXIT_GETSTR ; Yes, return to calling function
MOV [DI],AL ; Add character to buffer
INC DI ; Increment pointer
MOV AL,'.' ; Print period using fastchar function
INT 29h
JMP GETSTR_LOOP ; Loop again
EXIT_GETSTR:
MOV BYTE PTR [DI],0 ; Terminate string with a null
POP DI ; Restore DI
POP SI ; Restore SI
POP AX ; Restore AX
RET
;-----------------------------------------------------------------------;
; This procedure reads a character from the standard input device ;
; without echo. ;
; ;
; Uses: ;
; Nothing ;
; ;
; Returns: ;
; AL Character read ;
;-----------------------------------------------------------------------;
GET_CHAR:
MOV AH,07h ; Read character from standard input
INT 21h
RET
;-----------------------------------------------------------------------;
; This procedure compares two null-terminated strings. ;
; ;
; Uses: ;
; SI Source string ;
; DI Comparision string ;
; ;
; Returns: ;
; CF Set if strings are equal ;
;-----------------------------------------------------------------------;
STRCMP:
PUSH AX ; Save AX
PUSH SI ; Save SI
PUSH DI ; Save DI
STRCMP_LOOP:
MOV AL,[SI] ; Make a copy of the source character
CMP AL,[DI] ; Are the two characters equal?
JE ARE_EQUAL ; Yes, continue comparisons
CLC ; No, clear carry flag (return value)
JMP EXIT_STRCMP ; Return to calling function
ARE_EQUAL:
INC SI ; Increment data pointers
INC DI
CMP AL,0 ; Is source character a null?
JNE STRCMP_LOOP ; No, loop again
STC ; Yes, set carry flag (strings equal)
EXIT_STRCMP:
POP DI ; Restore DI
POP SI ; Restore SI
POP AX ; Restore AX
RET
MESSAGE1 DB 7,'System password protected.',13,10,0
MESSAGE2 DB 7,13,10,'Password incorrect.',13,10,0
MESSAGE3 DB 13,10,'System rebooting...',0
PROMPT DB 13,10,'Password: ',0
PASSWORD DB 'oki794',0
BUFFER DB 8 DUP('BUFFER ')
BACKSPACE DB 8,' ',8,0
_TEXT ENDS
END BEGIN